// pages/main/main.js
import config from '../../config'
const API = config.api
const app = getApp()
import {
    getLessLimitSizeImage
} from '../../utils/imageFile'
import {
    checkIdCard,
    checkHKMacao,
    IdentityCodeValid,
    isChineseName,
    checkLicense
} from '../../utils/util'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        idcardData: {
            name: '',
            num: '',
        },
        agentNameAliYun_success: 0,
        agentBackImgAliYun_success: 0,
        taiwanImgAliYun_success: 0,
        taiwanImgAliYun_back_success: 0,
        HongKongAndMacao_success: 0,
        HongKongAndMacao_back_success: 0,
        agentFrontImgAliYun_success: 0,
        agentBackImgUrl: "", //证件反面照 阿里云返回
        agentBackImg: "", //证件反面照 粤通卡图片链接
        agentFrontImgUrl: "", //证件正面照 调用阿里云图片上传返回图片路径
        agentFrontImg: "", //证件正面照 粤通卡图片链接
        taiWan_BackImgUrl: '', //台胞证背面阿里云返回
        taiWan_BackImg: '', //台胞证背面粤通卡图片链接
        taiWan_FrontImgUrl: '', //台胞证 阿里云返回
        taiWan_FrontImg: '', //台胞证 粤通卡图片链接
        KO_FrontImg: '', //港澳证 粤通卡图片链接
        KO_FrontImgUrl: '', //港澳证 阿里云返回
        KO_BackImg: '', //港澳证背面 粤通卡图片链接
        KO_BackImgUrl: '', //港澳证背面 阿里云返回
        certImgUrl: '', //营业执照 阿里云返回
        certImg: '', //营业执照粤通卡图片链接
        certifiType: 1,
        /*******↑↑↑↑↑非车主信息↑↑↑↑↑↑↑↑*********/
        isNonOwner: false,
        isChangeVehPlate: false,
        isShowRepeatConfirmation: false,
        confirmPaletNum: 0, //弹窗修改的车牌
        showMask: false,
        isUpdateStatus: false,
        // isVinConfirm: false,
        veh_license_pic_url1: '',
        veh_license_pic_url2: '',
        vehCertBackImgUrl: "", //行驶证反面照阿里云返回
        vehCertFrontImgUrl: "", //行驶证反面照阿里云返回
        vehCertBackImgAliYun_success: 0,
        vehCertFrontImgAliYun_success: 0,
        userinfo: {
            name: "",
            tel: "",
            address: "",
            detail: "",
        },
        license: {},
        ownerType: 0, //个人或公司
        ownerType1: '',
        vehicleType: 1,
        vehicleTypeIdx: 0,
        licensePlate: '',
        vehicle_color: 0,
        state: 1,
        interval: null,
        vehicle: {
            vehLength: '',
            vehHeight: '',
            vehWidth: ''
        },
        recognizedVIN:'',
        isChangeVin:false
    },
    BackPage() {
        wx.navigateBack({
            delta: 1
        });
    },
    onInput(e) {
        let type = e.target.dataset.type;
        let value = e.detail.value;
        if (type == "vehicle.plate_num.text") {
            this.setData({
                confirmPaletNum: 0
            })
        }
        if (type == "vehicle.vin.text") {
            this.setData({
                ownerType1: ""
            })
        }
        // this.data[type] = value
        this.setData({
            [type]: value.replace(/\s+/g, "")
        })
    },
    confirmTap(e) {
        console.log(e);
        let value = e.detail.value;
        this.getVinInfo(value);
    },
    blurVal(e) {
        console.log(e);
        let value = e.detail.value;
        this.getVinInfo(value);
    },
    getVinInfo(val) {
        app.http(API.orderGetVinInfo, {
            appKey: "000FX000035",
            mepName: "广汽本田",
            reqFrom: "76",
            vinCode: val
        }).then(res => {
            console.log(res);
            var obj = JSON.parse(res.rspData)
            var etcType = obj.object.etcType;
            this.setData({
                ownerType1: etcType
            })
        })
    },
    showVehCertFront() {
        this.setData({
            isShowVehCertFront: true,
            showMask: true
        })
    },
    hideVehCertFront() {
        this.setData({
            isShowVehCertFront: false,
            showMask: false
        })
    },
    hideVehCertBack() {
        this.setData({
            isShowVehCertBack: false,
            showMask: false
        })
    },
    //上传营业执照
    frontAgent(ev) {
        wx.chooseImage({
            count: 1, // 默认9 
            sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有 
            success: (res) => {
                let type = ev.currentTarget.dataset.type + '_success';
                this.setData({
                    [type]: 1,
                });
                // 读入本地图片
                let tempFilePaths = ''
                this.ossUploadFile(res.tempFilePaths[0]).then(ossRes => {
                    if (ossRes.code == 200) {
                        this.ocrBusinessLicense(res.tempFilePaths[0]).then(ocrRes => {
                            getLessLimitSizeImage('pressCanvas', res.tempFilePaths[0], 1, '750', (e) => {
                                tempFilePaths = e;
                                wx.getFileSystemManager().readFile({
                                    filePath: tempFilePaths,
                                    encoding: 'base64',
                                    success: (result) => {
                                        var rawBase64 = result.data;
                                        this.imageuploadFile({
                                            idCardPicFront: rawBase64
                                        }).then(imgRes => {

                                            if (imgRes.code == 200) {
                                                imgRes.rspData = JSON.parse(imgRes.rspData).object
                                                this.setData({
                                                    [type]: 2,
                                                })
                                                this.data.agentBackImg = imgRes.rspData.idCardPicFront;
                                                this.data.agentFrontImg = imgRes.rspData.idCardPicFront;
                                                if (this.data.isEdit) {
                                                    this.setData({
                                                        certImgUrl: ossRes.rspData,
                                                    })
                                                } else {
                                                    this.setData({
                                                        certImgUrl: ossRes.rspData,
                                                        license: ocrRes.data
                                                    })
                                                }

                                            } else {
                                                this.setData({
                                                    [type]: 4,
                                                })
                                            }

                                        }).catch(err => {
                                            this.setData({
                                                [type]: 4,
                                            })
                                        })

                                    },
                                    fail: err => {
                                        this.setData({
                                            [type]: 4,
                                        })
                                    },
                                });
                            })
                        }).catch(err => {
                            this.setData({
                                [type]: 3,
                            })
                        })

                    } else {
                        this.setData({
                            [type]: 4,
                        })
                    }

                }).catch(err => {
                    this.setData({
                        [type]: 4,
                    })
                })

            }
        })
    },
    //行驶证图片识别
    driverSuccess(e) {
        console.log(e);
        wx.showLoading({
            title: '识别中...',
            mask: true,
        });
        let ocrVehicleSide = e.currentTarget.dataset.side;
        let ocrVehicleType = e.currentTarget.dataset.type;
        let newVehicle = e.detail;
        let tempFilePaths = newVehicle.image_path;
        let type = ocrVehicleType + '_success';
        this.setData({
            isShowVehCertFront: false,
            isShowVehCertBack: false,
            showMask: false
        })
        if (ocrVehicleSide == "face" && newVehicle.type != 0 || ocrVehicleSide == "back" && newVehicle.type != 1) {
            this.setData({
                [type]: 3,
            });
            return;
        } else {
            this.setData({
                [type]: 1,
            });
        }
        let vehicle = this.data.vehicle;
        if (ocrVehicleSide == "back") {
            if (newVehicle.overall_size.text) {
                let overall_dimension = newVehicle.overall_size.text.replace(/[^0-9]+/g, ',').split(',');
                newVehicle.vehHeight = overall_dimension[2];
                newVehicle.vehLength = overall_dimension[0];
                newVehicle.vehWidth = overall_dimension[1];
            } else {
                newVehicle.vehHeight = "";
                newVehicle.vehLength = "";
                newVehicle.vehWidth = "";
            }
            if (!newVehicle.vehLength) {
                console.log(newVehicle.vehLength)
            }
        } else {
            //代办
            if (this.data.ownerType == 0) {
              console.log(this.data.etcInfo);
                if (e.detail.owner.text != this.data.etcInfo.saveAccountInfoRequest.organ) {
                    this.setData({
                        isNonOwner: true
                    })
                }
            }
        }
        this.setData({
            vehicle: {
                ...vehicle,
                ...newVehicle
            }
        });
        this.drivingLicenseImage(ocrVehicleSide, type, tempFilePaths, ocrVehicleType);
        this.getVinInfo(newVehicle.vin.text);
    },
    driverSuccessvin(e){
        console.log(e);
        // let ocrVehicleSide = e.currentTarget.dataset.side;
        // let ocrVehicleType = e.currentTarget.dataset.type;
        let newVehicle = e.detail;
        // let tempFilePaths = newVehicle.image_path;
        // let type = ocrVehicleType + '_success';
        // if (ocrVehicleSide == "face" && newVehicle.type != 0 || ocrVehicleSide == "back" && newVehicle.type != 1) {
        //     this.setData({
        //         [type]: 3,
        //     });
        //     return;
        // } else {
        //     this.setData({
        //         [type]: 1,
        //     });
        // }
        let vehicle = this.data.vehicle;
        // if (ocrVehicleSide == "back") {
        //     if (newVehicle.overall_size.text) {
        //         let overall_dimension = newVehicle.overall_size.text.replace(/[^0-9]+/g, ',').split(',');
        //         newVehicle.vehHeight = overall_dimension[2];
        //         newVehicle.vehLength = overall_dimension[0];
        //         newVehicle.vehWidth = overall_dimension[1];
        //     } else {
        //         newVehicle.vehHeight = "";
        //         newVehicle.vehLength = "";
        //         newVehicle.vehWidth = "";
        //     }
        //     if (!newVehicle.vehLength) {
        //         console.log(newVehicle.vehLength)
        //     }
        // } else {
        //     //代办
        //     if (this.data.ownerType == 0) {
        //         if (e.detail.owner.text != this.data.etcInfo.saveAccountInfoRequest.organ) {
        //             this.setData({
        //                 isNonOwner: true
        //             })
        //         }
        //     }
        // }
        this.setData({
            vehicle: {
                ...vehicle,
                ...newVehicle
            }
        });
        console.log(newVehicle.vin.text);
        this.getVinInfo(newVehicle.vin.text);
    },
    //确认车辆识别号
    // vinCarInfoConfirm() {
    //     this.setData({
    //         isVinConfirm: true
    //     });
    // },
    //营业执照识别
    ocrBusinessLicense(img) {
        return new Promise((resolve, reject) => {
            wx.getFileSystemManager().readFile({
                filePath: img,
                encoding: 'base64',
                success: (result) => {
                    var rawBase64 = result.data;
                    app.http(API.ocrBusinessLicense, {
                        image: rawBase64,
                        user_id: this.data.userId
                    }).then(res => {
                        if (res.errcode == 200) {
                            if (res.data.success == false) {
                                reject(err)
                            } else {
                                resolve(res)
                            }
                        } else {
                            reject(err)
                        }
                    }).catch(err => {
                        reject(err)
                    })
                },
                fail: err => {
                    reject(err)
                },
            })

        })
    },
    //阿里云上传
    ossUploadFile(img) {
        return new Promise((resolve, reject) => {
            wx.getFileSystemManager().readFile({
                filePath: img,
                encoding: 'base64',
                success: (result) => {
                    var rawBase64 = result.data;
                    app.http(API.apiUploadOss, {
                        image: rawBase64,
                        user_id: this.data.userId
                    }).then(res => {
                        console.log(res);
                        resolve(res)
                    }).catch(err => {
                        console.log(err);
                        reject(err)
                    })
                },
                fail: err => {
                    reject(err)
                },
            })

        })
    },
    showVehCertBack() {
        this.setData({
            isShowVehCertBack: true,
            showMask: true
        })
    },
    //粤通卡图片上传
    imageuploadFile(obj) {
        return new Promise((resolve, reject) => {
            app.http(API.apiUploadPhotoSrc, obj).then(res => {
                resolve(res)
            }).catch(err => {
                reject(err)
            })
        })
        // return new Promise((resolve, reject) => {
        // 	app.http(API.apiUploadPhoto, obj).then(res => {
        // 		resolve(res)
        // 	}).catch(err => {
        // 		reject(err)
        // 	})
        // })
    },
    //身份证识别，调用腾讯ocr
    idCardSuccess(e) {
        wx.showLoading({
            title: '识别中...',
            mask: true,
        });
        let tempFilePaths = e.detail.image_path;
        let ocrVehicleType = e.currentTarget.dataset.type;
        let side = e.currentTarget.dataset.side;
        let type = ocrVehicleType + '_success';
        if (e.currentTarget.dataset.side == 'face') {
            if (this.data.isEdit) {
                this.setData({
                    ['idcardData.address']: e.detail.address.text
                })
            } else {
                this.setData({
                    ['idcardData.name']: e.detail.name.text,
                    ['idcardData.num']: e.detail.id.text,
                    ['idcardData.address']: e.detail.address.text
                })
            }

            this.idCardLicenseImage(ocrVehicleType, type, side, tempFilePaths)
        } else {
            let trx_id_stime = ''
            let trx_id_etime = ''
            let time = e.detail.valid_date.text.split('-')
            trx_id_etime = time[1]
            trx_id_stime = time[0]
            this.setData({
                ['idcardData.trx_id_stime']: trx_id_stime,
                ['idcardData.trx_id_etime']: trx_id_etime,
            })
            this.idCardLicenseImage(ocrVehicleType, type, side, tempFilePaths)
        }
    },
    //身份证图片上传
    idCardLicenseImage(ocrVehicleType, type, side, tempFilePaths) {
        this.setData({
            [type]: 1,
        });
        this.ossUploadFile(tempFilePaths).then(ossRes => {
            if (ossRes.code == 200) {
                getLessLimitSizeImage('pressCanvas', tempFilePaths, 1, '750', (e) => {
                    wx.getFileSystemManager().readFile({
                        filePath: e,
                        encoding: 'base64',
                        success: (result) => {
                            let imgFileKey = ''
                            if (side == "back") {
                                imgFileKey = 'idCardPicBack'
                            } else {
                                imgFileKey = 'idCardPicFront'
                            }
                            var rawBase64 = result.data;
                            this.imageuploadFile({
                                [imgFileKey]: rawBase64
                            }).then(res => {
                                if (res.code == 200) {
                                    res.rspData = JSON.parse(res.rspData).object
                                    if (ossRes.code == 200) {
                                        this.setData({
                                            [type]: 2,
                                        });
                                        if (side == 'face') {
                                            this.data.agentFrontImg = res.rspData.idCardPicFront;
                                            this.setData({
                                                agentFrontImgUrl: ossRes.rspData,
                                            })
                                        } else {
                                            this.data.agentBackImg = res.rspData.idCardPicBack;
                                            this.setData({
                                                agentBackImgUrl: ossRes.rspData
                                            })
                                        }
                                        wx.hideLoading()
                                    } else {
                                        this.setData({
                                            [type]: 3,
                                        })
                                        wx.showToast({
                                            title: '图片上传失败',
                                            icon: 'none',
                                            duration: 3000,
                                            mask: false
                                        });
                                    }
                                } else {
                                    this.setData({
                                        [type]: 3,
                                    })
                                    wx.showToast({
                                        title: '图片上传失败',
                                        icon: 'none',
                                        duration: 3000,
                                        mask: false
                                    });
                                }

                            }).catch(err => {
                                console.log(err)
                                this.setData({
                                    [type]: 3,
                                })
                                wx.showToast({
                                    title: '图片上传失败',
                                    icon: 'none',
                                    duration: 3000,
                                    mask: false
                                });
                            })
                        },
                        fail: err => {
                            wx.hideLoading()
                            console.log('读取本地图片出错', err);
                        },
                    });
                })
            } else {
                this.setData({
                    [type]: 3,
                })
                wx.hideLoading()
            }

        }).catch(err => {
            this.setData({
                [type]: 3,
            })
            wx.showToast({
                title: '图片上传失败',
                icon: 'none',
                duration: 3000,
                mask: false
            });
        })


    },
    /**
     * 台湾，港澳证上传
     */
    frontimage: function (ev) {
        var _this = this;
        wx.chooseImage({
            count: 1, // 默认9 
            sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有 
            success: (res) => {
                this.setData({
                    [ev.currentTarget.dataset.type + '_success']: 1,
                });
                this.ossUploadFile(res.tempFilePaths[0]).then(ossRes => {
                    if (ossRes.code == 200) {
                        // 读入本地图片
                        let tempFilePaths = ''
                        getLessLimitSizeImage('pressCanvas', res.tempFilePaths[0], 1, '750', (e) => {
                            tempFilePaths = e;
                            wx.getFileSystemManager().readFile({
                                filePath: tempFilePaths,
                                encoding: 'base64',
                                success: (result) => {
                                    let imgFileKey = ''
                                    if (ev.currentTarget.dataset.side == "back") {
                                        imgFileKey = 'idCardPicBack'
                                    } else {
                                        imgFileKey = 'idCardPicFront'
                                    }

                                    var rawBase64 = result.data;
                                    let type = ev.currentTarget.dataset.type + '_success';
                                    this.imageuploadFile({
                                        [imgFileKey]: rawBase64
                                    }).then(res => {
                                        if (res.code == 200) {
                                            res.rspData = JSON.parse(res.rspData).object
                                            this.setData({
                                                [type]: 2,
                                            })
                                            if (this.data.certifiType == 10) {
                                                if (ev.currentTarget.dataset.side == "back") {
                                                    this.data.KO_BackImg = res.rspData.idCardPicBack;
                                                    this.setData({
                                                        KO_BackImgUrl: ossRes.rspData
                                                    })
                                                } else {
                                                    this.data.KO_FrontImg = res.rspData.idCardPicFront;
                                                    this.setData({
                                                        KO_FrontImgUrl: ossRes.rspData
                                                    })
                                                }

                                            } else {
                                                if (ev.currentTarget.dataset.side == "back") {
                                                    this.data.taiWan_BackImg = res.rspData.idCardPicBack;
                                                    this.setData({
                                                        taiWan_BackImgUrl: ossRes.rspData
                                                    })
                                                } else {
                                                    this.data.taiWan_FrontImg = res.rspData.idCardPicFront;
                                                    this.setData({
                                                        taiWan_FrontImgUrl: ossRes.rspData
                                                    })
                                                }
                                            }
                                        } else {
                                            this.setData({
                                                [type]: 3,
                                            })
                                        }

                                    }).catch(err => {
                                        this.setData({
                                            [type]: 3,
                                        })
                                    })
                                },
                                fail: err => {
                                    // console.log('读取本地图片出错', err);
                                },
                            });
                        })


                    } else {
                        this.setData({
                            [type]: 3,
                        })
                    }
                }).catch(err => {
                    this.setData({
                        [type]: 3,
                    })
                });

            }
        })
    },
    //行驶证图片上传
    drivingLicenseImage(ocrVehicleSide, imageType, tempFilePaths, ocrVehicleType) {
        this.ossUploadFile(tempFilePaths).then(ossRes => {
            if (ossRes.code == 200) {
                getLessLimitSizeImage('pressCanvas', tempFilePaths, 1, '375', (e) => {
                    wx.getFileSystemManager().readFile({
                        filePath: e,
                        encoding: 'base64',
                        success: (result) => {
                            var rawBase64 = result.data;
                            let imgFileKey = ''
                            if (ocrVehicleSide == 'face') {
                                imgFileKey = 'vehLicensePicFront'
                            } else {
                                imgFileKey = 'vehLicensePicBack'
                            }
                            this.imageuploadFile({
                                [imgFileKey]: rawBase64
                            }).then(res => {
                                if (res.code == 200) {
                                    res.rspData = JSON.parse(res.rspData).object
                                    this.setData({
                                        [imageType]: 2,
                                    });

                                    //正反面都识别成功后，进行判断参数缺少情况
                                    if (this.data.vehCertFrontImgAliYun_success == 2) {
                                        let errInfo = [];
                                        if (this.data.licensePlate != this.data.vehicle.plate_num.text) {
                                            errInfo.push("车牌号码")
                                        }
                                        if (this.data.vehicle.engine_num.text == "") {
                                            errInfo.push("发动机号");

                                        }
                                        if (this.data.vehicle.vin.text == "") {
                                            errInfo.push("车辆识别代号");
                                            this.setData({
                                                isVin: true
                                            })
                                        } else {
                                            this.setData({
                                                isVin: false
                                            })
                                        }
                                        if (this.data.vehicle.vehicle_type.text == "") {
                                            errInfo.push("行驶证车辆类型");
                                            this.setData({
                                                is_vehicle_type: true
                                            })
                                        } else {
                                            this.setData({
                                                is_vehicle_type: false
                                            })
                                        }
                                        let issue_date = this.data.vehicle.issue_date.text;
                                        if (new Date(issue_date.replace(/-/g, "/")) == 'Invalid Date' || new Date(issue_date.replace(/-/g, "/")) == '' || new Date(issue_date.replace(/-/g, "/")) == null) {
                                            errInfo.push("发证日期");
                                            this.setData({
                                                is_issue_date: true,
                                                'vehicle.issue_date.text': ''
                                            })
                                        } else {
                                            let old_date = new Date(issue_date.replace(/-/g, "/")).getTime();
                                            let new_date = new Date().getTime();
                                            if (old_date > new_date) {
                                                errInfo.push("发证日期");
                                                this.setData({
                                                    is_issue_date: true,
                                                    'vehicle.issue_date.text': ''
                                                })
                                            } else {
                                                this.setData({
                                                    is_issue_date: false
                                                })
                                            }
                                        }
                                        let register_date = this.data.vehicle.register_date.text;
                                        if (new Date(register_date.replace(/-/g, "/")) == 'Invalid Date') {
                                            errInfo.push("注册日期");
                                            this.setData({
                                                is_register_date: true,
                                                'vehicle.register_date.text': ''
                                            })
                                        } else {
                                            let old_date = new Date(register_date.replace(/-/g, "/")).getTime();
                                            let new_date = new Date().getTime();
                                            if (old_date > new_date) {
                                                errInfo.push("注册日期");
                                                this.setData({
                                                    is_register_date: true,
                                                    'vehicle.register_date.text': ''
                                                })
                                            } else {
                                                this.setData({
                                                    is_register_date: false
                                                })
                                            }
                                        }
                                        if (errInfo.length != 0) {
                                            let title = errInfo.join('、')
                                            wx.showModal({
                                                title: '提示',
                                                showCancel: false,
                                                content: `识别到${title}信息有误，请手动修改`,
                                            })
                                        }
                                    } else if (this.data.vehCertBackImgAliYun_success == 2) {
                                        let errInfo = []
                                        if (!this.data.vehicle.prepare_quality || this.data.vehicle.prepare_quality.text == "" || this.data.vehicle.prepare_quality.tex == "-") {
                                            errInfo.push("整备质量");
                                            this.setData({
                                                is_prepare_quality: true
                                            })
                                        } else {
                                            this.setData({
                                                is_prepare_quality: false
                                            })
                                        }
                                        if (!this.data.vehicle.total_quality || this.data.vehicle.total_quality.text == "" || this.data.vehicle.total_quality.tex == "-") {
                                            errInfo.push("总质量");
                                            this.setData({
                                                is_total_quality: true
                                            })
                                        } else {
                                            this.setData({
                                                is_total_quality: false
                                            })
                                        }
                                        if (!this.data.vehicle.vehWidth || this.data.vehicle.vehWidth == "" || this.data.vehicle.vehWidth < 1400 || this.data.vehicle.vehWidth > 2200) {
                                            errInfo.push("车宽");
                                            this.setData({
                                                isVehWidth: true
                                            })
                                        } else {
                                            this.setData({
                                                isVehWidth: false
                                            })
                                        }
                                        if (!this.data.vehicle.vehHeight || this.data.vehicle.vehHeight == "" || this.data.vehicle.vehHeight < 1100 || this.data.vehicle.vehHeight > 2500) {
                                            errInfo.push("车高");
                                            this.setData({
                                                isVehHeight: true
                                            })
                                        } else {
                                            this.setData({
                                                isVehHeight: false
                                            })
                                        }
                                        if (!this.data.vehicle.vehLength || this.data.vehicle.vehLength == "" || this.data.vehicle.vehLength < 2900 || this.data.vehicle.vehLength > 6200) {
                                            errInfo.push("车长");
                                            this.setData({
                                                isVehLength: true
                                            })
                                        } else {
                                            this.setData({
                                                isVehLength: false
                                            })
                                        }

                                        if (errInfo.length != 0) {
                                            let title = errInfo.join('、')
                                            wx.showModal({
                                                title: '提示',
                                                showCancel: false,
                                                content: `识别到${title}信息有误，请手动修改`,
                                            })
                                        }
                                    }


                                    if (ocrVehicleSide == 'face') {
                                        this.data.veh_license_pic_url1 = res.rspData.vehLicensePicFront
                                        this.setData({
                                            vehCertFrontImgUrl: ossRes.rspData
                                        })
                                    } else {
                                        this.data.veh_license_pic_url2 = res.rspData.vehLicensePicBack
                                        this.setData({
                                            vehCertBackImgUrl: ossRes.rspData
                                        })
                                    }
                                    wx.hideLoading()
                                } else {
                                    this.setData({
                                        [imageType]: 4,
                                    });
                                    wx.hideLoading()
                                }
                            })
                        },
                        fail: err => {
                            wx.hideLoading()
                            this.setData({
                                [imageType]: 4,
                            });
                        },
                    });
                })
            } else {
                this.setData({
                    [imageType]: 4,
                })
                wx.showToast({
                    title: '行驶证图片上传失败',
                    icon: 'none',
                    duration: 3000,
                    mask: false
                });
                wx.hideLoading()
            }
        }).catch(err => {
            this.setData({
                [imageType]: 4,
            })
            wx.showToast({
                title: '行驶证图片上传失败',
                icon: 'none',
                duration: 3000,
                mask: false
            });
        })


    },
    //选择要修改的车牌
    radioChange(e) {
        this.setData({
            confirmPaletNum: e.detail.value
        })
    },

    //取消选择
    hideChangeVehPlate() {
        this.setData({
            isChangeVehPlate: false
        })
    },
    //选择车牌修改确认
    confirmPalet() {
        if (this.data.confirmPaletNum == 0) {
            this.hideChangeVehPlate()
        } else {
            this.addCarInfoConfirm()
        }

    },
    // 修改行驶证车辆识别号
    confirmVin(){
        this.setData({
            isChangeVin: false
        })
    },
    addCarInfoConfirm() {
        if (this.data.ownerType1 == "") {
            wx.showToast({
                title: '检测车辆ETC类型错误',
                icon: 'none',
                duration: 3000
            });
            return;
        }
        // if (!this.data.isVinConfirm) {
        //     wx.showToast({
        //         title: '请核对车辆识别号',
        //         icon: 'none',
        //         image: '',
        //         duration: 3000
        //     });
        //     return;
        // }
        if (this.data.vehCertFrontImgAliYun_success != 2) {
            wx.showToast({
                title: '请上传行驶证正面照',
                icon: 'none',
                image: '',
                duration: 3000
            });
            return;
        }
        if (this.data.vehCertBackImgAliYun_success != 2) {
            wx.showToast({
                title: '请上传行驶证反面照',
                icon: 'none',
                image: '',
                duration: 3000
            });
            return;
        }
        if (this.data.vehicle.engine_num.text == "") {
            wx.showToast({
                title: '请核对发动机号',
                icon: 'none',
                image: '',
                duration: 3000
            });
            return;
        }
        if (this.data.vehicle.vin.text == "") {
            wx.showToast({
                title: '请核对车辆识别代号',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                isVin: true
            })
            return;
        }
        if (!this.data.vehicle.prepare_quality || this.data.vehicle.prepare_quality.text == "" || this.data.vehicle.prepare_quality.tex == "-") {
            wx.showToast({
                title: '请核对整备质量',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                is_prepare_quality: true
            })
            return;
        }
        if (!this.data.vehicle.total_quality || this.data.vehicle.total_quality.text == "" || this.data.vehicle.total_quality.tex == "-") {
            wx.showToast({
                title: '请核对总质量',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                is_total_quality: true
            })
            return;
        }
        if (this.data.vehicle.vehWidth == "" || this.data.vehicle.vehWidth < 1400 || this.data.vehicle.vehWidth > 2200) {
            wx.showToast({
                title: '请核对车宽',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                isVehWidth: true
            })
            return;
        }
        if (this.data.vehicle.vehHeight == "" || this.data.vehicle.vehHeight < 1100 || this.data.vehicle.vehHeight > 2500) {
            wx.showToast({
                title: '请核对车高',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                isVehHeight: true
            })
            return;
        }
        if (this.data.vehicle.vehLength == "" || this.data.vehicle.vehLength < 2900 || this.data.vehicle.vehLength > 6200) {
            wx.showToast({
                title: '请核对车长',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                isVehLength: true
            })
            return;
        }
        if (this.data.vehicle.vehicle_type.text == "") {
            wx.showToast({
                title: '请核对行驶证车辆类型',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                is_vehicle_type: true
            })
            return;
        }
        let issue_date = this.data.vehicle.issue_date.text;
        if (new Date(issue_date.replace(/-/g, "/")) == 'Invalid Date') {
            wx.showToast({
                title: '请核对行驶证发证日期',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                is_issue_date: true
            })
            return;
        } else if (!this.strDateTime(issue_date)) {
            wx.showToast({
                title: '请核对行驶证发证日期是否正确',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                is_issue_date: true
            })
            return;
        } else {
            let old_date = new Date(issue_date.replace(/-/g, "/")).getTime();
            let new_date = new Date().getTime();
            if (old_date > new_date) {
                wx.showToast({
                    title: '您当前输入的发证日期大于现在时间',
                    icon: 'none',
                    image: '',
                    duration: 3000
                });
                this.setData({
                    is_issue_date: true
                })
                return;
            }

        }
        let register_date = this.data.vehicle.register_date.text;
        if (new Date(register_date.replace(/-/g, "/")) == 'Invalid Date') {
            wx.showToast({
                title: '请核对行驶证注册日期',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                is_register_date: true
            })
            return;
        } else if (!this.strDateTime(register_date)) {
            wx.showToast({
                title: '请核对行驶证注册日期是否正确',
                icon: 'none',
                image: '',
                duration: 3000
            });
            this.setData({
                is_register_date: true
            })
            return;
        } else {
            let old_date = new Date(register_date.replace(/-/g, "/")).getTime();
            let new_date = new Date().getTime();
            if (old_date > new_date) {
                wx.showToast({
                    title: '您当前输入注册日期大于现在时间',
                    icon: 'none',
                    image: '',
                    duration: 3000
                });
                this.setData({
                    is_register_date: true
                })
                return;
            }
        }
        if (this.data.isNonOwner) {
            var agentName = '';
            if (this.data.certifiType == 1) {
                agentName = this.data.idcardData.name;
                let codeValid = IdentityCodeValid(this.data.idcardData.num)
                if (this.data.agentFrontImgAliYun_success != 2) {
                    wx.showToast({
                        title: '请上传身份证正面',
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
                if (this.data.agentBackImgAliYun_success != 2) {
                    wx.showToast({
                        title: '请上传身份证背面',
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
                if (this.data.idcardData.name == '') {
                    wx.showToast({
                        title: '请核对车主姓名',
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
                if (this.data.idcardData.num == '' || !codeValid) {
                    wx.showToast({
                        title: '请核对身份证号',
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
            } else if (this.data.certifiType == 10) {
                this.data.idcardData.HongKongAndMacaonNum = this.data.idcardData.num
                agentName = this.data.idcardData.name
                let codeValid = checkHKMacao(this.data.idcardData.HongKongAndMacaonNum);
                if (this.data.HongKongAndMacao_success != 2) {
                    wx.showToast({
                        title: '请上传证件正面照',
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
                if (this.data.HongKongAndMacao_back_success != 2) {
                    wx.showToast({
                        title: '请上传证件背面照',
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
                if (this.data.idcardData.HongKongAndMacaoName == '') {
                    wx.showToast({
                        title: '请核对车主姓名',
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }

                if (!codeValid.errCode) {
                    wx.showToast({
                        title: codeValid.errMsg,
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
            } else if (this.data.certifiType == 11) {
                this.data.idcardData.taiWanNum = this.data.idcardData.num
                agentName = this.data.idcardData.name
                let codeValid = checkIdCard(this.data.idcardData.taiWanNum);

                if (this.data.taiwanImgAliYun_success != 2) {
                    wx.showToast({
                        title: '请上传证件正面照',
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
                if (this.data.taiwanImgAliYun_back_success != 2) {
                    wx.showToast({
                        title: '请上传证件背面照',
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
                if (this.data.idcardData.taiWanName == '') {
                    wx.showToast({
                        title: '请核对车主姓名',
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
                if (codeValid.respCode != 0) {
                    wx.showToast({
                        title: codeValid.respDesc,
                        icon: 'none',
                        image: '',
                        duration: 3000
                    });
                    return;
                }
            }
            if (!isChineseName(agentName)) {
                wx.showToast({
                    title: '请输入合法的车主姓名',
                    icon: 'none',
                    image: '',
                    duration: 3000
                });
                return;
            }
        }

        if (this.data.ownerType == 1) {
            if (this.data.agentNameAliYun_success != 2) {
                wx.showToast({
                    title: '请上传营业执照',
                    icon: 'none',
                    image: '',
                    duration: 3000
                });
                return;
            }
            if (this.data.license.name == '') {
                wx.showToast({
                    title: '请输入公司名称',
                    icon: 'none',
                    image: '',
                    duration: 3000
                });
                return;
            }
            if (!checkLicense(this.data.license.reg_num)) {
                wx.showToast({
                    title: '请核对统一社会信用代码',
                    icon: 'none',
                    image: '',
                    duration: 3000
                });
                return;
            }
        }

        if (this.data.isNonOwner) {
            if (agentName != this.data.vehicle.owner.text) {
                wx.showModal({
                    title: '提示',
                    content: '车辆所有人和车主姓名不一致，请注意核对证件是否同一人。',
                    showCancel: false,
                    success(res) {}
                })
                return;
            }

        }

        if (this.data.licensePlate != this.data.vehicle.plate_num.text && this.data.confirmPaletNum == 0) {
            this.setData({
                isChangeVehPlate: true
            })
            return;
        }
        this.setData({
            isChangeVin:true, 
            isShowRepeatConfirmation: true,
            showMask: true,
            remindernum: 5,
            interval: setInterval(() => {
                if (this.data.remindernum == 0) {
                    clearInterval(this.data.interval);
                    this.setData({
                        interval: null
                    })
                } else {
                    this.setData({
                        remindernum: this.data.remindernum - 1
                    })
                }
            }, 1000)
        })
    },
    close() {
        this.setData({
            isShowRepeatConfirmation: false,
            showMask: false
        })
    },
    //日期校验
    strDateTime(str) {
        var r = str.match(/^(\d{4})(-|\/)(\d{2})\2(\d{2})$/);
        if (r == null) return false;
        var d = new Date(r[1], r[3] - 1, r[4]);
        return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]);
    },
    isObj(object) { // 判断是否是object
        return object && typeof (object) == 'object' && Object.prototype.toString.call(object).toLowerCase() == "[object object]";
    },
    isArray(object) { // 判断是否是array
        return Object.prototype.toString.call(object) === '[object Array]';
    },
    checkVehicle() {
        let vehicle_color = this.data.vehicle_color
        if (this.data.confirmPaletNum != 0) {
            vehicle_color = this.data.confirmPaletNum.length == 8 ? 4 : 0;
        }
        app.http(API.apiCheckVehicle, {
            qzFlag: 1,
            temporaryFlag: 0,
            vehicle_color: vehicle_color,
            vehicle_code_flag: this.data.ownerType1,
            vehicle_plate: this.data.confirmPaletNum == 0 ? this.data.vehicle.plate_num.text : this.data.confirmPaletNum,
            // zhtxMobile: this.data.etcInfo.saveAccountInfoRequest.mobilephone
            zhtxMobile: ''
        }).then(res => {
            if (res.code == 200) {
                let rspData = JSON.parse(res.rspData)
                if (rspData.success) {
                    if (this.isObj(rspData.object)) {
                        if (rspData.object.return_code == '0000') {
                            this.addCarInfo()
                        } else {
                            wx.hideLoading()
                            wx.showModal({
                                title: '提示',
                                content: rspData.object.return_msg,
                                confirmColor: '#005866',
                                showCancel: false,
                                success(res) {}
                            })
                        }
                    } else {
                        if (this.isArray(rspData.object)) {
                            if (rspData.object[0].return_code == '0000') {
                                this.addCarInfo()
                            }
                        } else {
                            wx.hideLoading()
                            wx.showModal({
                                title: '提示',
                                content: rspData.object[0].return_msg,
                                confirmColor: '#005866',
                                showCancel: false,
                                success(res) {}
                            })
                        }
                    }
                } else {
                    wx.hideLoading()
                    wx.showModal({
                        title: '提示',
                        content: rspData.msg,
                        confirmColor: '#005866',
                        showCancel: false,
                        success(res) {}
                    })
                }
            } else {
                wx.hideLoading()
                wx.showModal({
                    title: '提示',
                    content: res.message,
                    confirmColor: '#005866',
                    showCancel: false,
                    success(res) {}
                })
            }
        }).catch(err => {
            wx.showToast({
                title: err,
                icon: 'none',
                duration: 3000,
                mask: false
            });
        })
    },
    //添加车辆信息
    addCarInfo() {
        let owner_id_type = '',
            owner_id_num = '',
            agentBackImgUrl = '',
            agentFrontImgUrl = '',
            owner_picurl1 = '',
            owner_picurl2 = '';
        if (this.data.ownerType == 0 && this.data.isNonOwner) {
            owner_id_type = this.data.certifiType;
            if (this.data.certifiType == 1) {
                agentBackImgUrl = this.data.agentBackImgUrl;
                owner_picurl2 = this.data.agentBackImg;
                owner_picurl1 = this.data.agentFrontImg;
                agentFrontImgUrl = this.data.agentFrontImgUrl;
                owner_id_num = this.data.idcardData.num;
            } else if (this.data.certifiType == 10) {
                agentBackImgUrl = this.data.KO_BackImgUrl;
                agentFrontImgUrl = this.data.KO_FrontImgUrl;
                owner_picurl2 = this.data.KO_BackImg;
                owner_picurl1 = this.data.KO_FrontImg;
                owner_id_num = this.data.idcardData.HongKongAndMacaonNum
            } else {
                owner_id_num = this.data.idcardData.taiWanNum
                agentBackImgUrl = this.data.taiWan_BackImgUrl;
                agentFrontImgUrl = this.data.taiWan_FrontImgUrl;
                owner_picurl2 = this.data.taiWan_BackImg;
                owner_picurl1 = this.data.taiWan_FrontImg;
            }
        };
        if (this.data.ownerType == 1) {
            owner_id_type = 2;
            owner_picurl2 = this.data.agentBackImg;
            owner_picurl1 = this.data.agentFrontImg;
            agentBackImgUrl = this.data.certImgUrl;
            agentFrontImgUrl = this.data.certImgUrl;
            owner_id_num = this.data.license.reg_num
        };
        wx.showLoading({
            title: '正在提交资料',
            mask: true,
        });
        let vehicle_color = this.data.vehicle_color
        if (this.data.confirmPaletNum != 0) {
            vehicle_color = this.data.confirmPaletNum.length == 8 ? 4 : 0;
        }
        // 1198接口
        let maintenance_mass = this.data.vehicle.prepare_quality && this.data.vehicle.prepare_quality.text ? parseInt(this.data.vehicle.prepare_quality.text) : 0;
        let total_mass = this.data.vehicle.total_quality && this.data.vehicle.total_quality.text ? parseInt(this.data.vehicle.total_quality.text) : 0;
        let permitted_tow_weight = this.data.vehicle.lead_quality && this.data.vehicle.lead_quality.text ? parseInt(this.data.vehicle.lead_quality.text) : 0;
        let vehicle_capacity = this.data.vehicle.load_quality && this.data.vehicle.load_quality.text ? parseInt(this.data.vehicle.load_quality.text) : 0;
        var saveCarInfoRequest = {
            owner_id_type,
            owner_id_num,
            owner_picurl1,
            owner_picurl2,
            user_type: 8,
            veh_license_pic_url1: this.data.veh_license_pic_url1,
            veh_license_pic_url2: this.data.veh_license_pic_url2,
            applyExtInfo: {
                vehCertBackImgUrl: this.data.vehCertBackImgUrl,
                vehCertFrontImgUrl: this.data.vehCertFrontImgUrl,
                agentBackImgUrl: agentBackImgUrl,
                agentFrontImgUrl: agentFrontImgUrl,
            },
            "vehicle_type": '0', //0:客车 1:货车 2:专项作业车
            "vehicle_plate": this.data.confirmPaletNum == 0 ? this.data.vehicle.plate_num.text : this.data.confirmPaletNum, //车牌号
            "vehicle_color": vehicle_color, //车牌色 0-蓝色，1-黄色，2-黑色，3-白色，4- 渐变绿色 5- 黄绿双拼色 6-//蓝白渐变色 9- 未确定 11-绿色 12-红色
            "approved_count": parseInt(this.data.vehicle.passengers_num.text), //核定载人数
            "vehicle_capacity": vehicle_capacity ? vehicle_capacity : 0, //核定载质量
            "vehicle_axles": 2, //车轴数
            "vehicle_wheels": 4, //轮数
            "vehicle_txtclass": this.data.vehicle.vehicle_type.text, //行驶证车辆类型
            "owner": this.data.vehicle.owner.text, //车主姓名
            "func_type": this.data.vehicle.use_character.text,
            "factory_code": this.data.vehicle.model.text, //行驶证品牌型号
            "engine_code": this.data.vehicle.engine_num.text, //发动机号
            "vehicle_code": this.data.vehicle.vin.text, //车辆识别代号
            "vehicle_info_address": this.data.vehicle.addr.text, //地址
            "issue_date": this.data.vehicle.issue_date.text, //发证日期
            "register_date": this.data.vehicle.register_date.text, //注册日期
            "vehicle_height": this.data.vehicle.vehHeight, //车高
            "vehicle_length": this.data.vehicle.vehLength, //车长
            "vehicle_width": this.data.vehicle.vehWidth, //车宽
            "total_mass": total_mass ? total_mass : 0, //总质量
            "maintenance_mass": maintenance_mass ? maintenance_mass : 0, //整备质量
            "permitted_tow_weight": permitted_tow_weight ? permitted_tow_weight : 0, //准牵引总质量
            "car_info_save_source": '1', //0:交管获取;1:OCR识别
            "userId": this.data.userId, //用户ID
            "vehicle_code_flag": this.data.ownerType1 //车辆连接类型
        }
        this.setData({
            saveCarInfoRequest
        })
        // return false;
        app.http(API.apiSaveCarInfo, saveCarInfoRequest).then(res => {
            console.log(res);
            if (res.code == 200) {
                this.productDetail()
            } else {
                wx.showModal({
                    title: '提示',
                    content: res.message,
                    confirmColor: '#005866',
                    showCancel: false,
                    success(res) {}
                })
                wx.hideLoading();
                this.close()
            }
        }).catch(err => {
            this.close()
            wx.showToast({
                title: err.message,
                icon: 'none',
                duration: 3000,
                mask: false
            });
        })
    },
    //产品推荐查询
    productDetail() {
        wx.showLoading({
            title: '提交资料中...',
            mask: true
        })
        debugger
        app.http(API.apiProductDetail, {
            userId: this.data.userId,
            bind_tel: this.data.etcInfo.saveAccountInfoRequest.mobilephone,
            idtype: this.data.etcInfo.saveAccountInfoRequest.idtype,
            approved_count: this.data.saveCarInfoRequest.approved_count,
            vehicle_length: this.data.saveCarInfoRequest.vehicle_length,
            vehicle_plate: this.data.saveCarInfoRequest.vehicle_plate,
            vehicle_color: this.data.saveCarInfoRequest.vehicle_color,
            vehicle_axles: this.data.saveCarInfoRequest.vehicle_axles,
            total_mass: this.data.saveCarInfoRequest.total_mass,
            car_type: 0,
            productId: '02',
            user_type: 8,
        }).then(res => {
            if (res.code == 200) {
                this.submitOrder();
            } else {
                wx.showModal({
                    title: '提示',
                    content: res.message,
                    confirmColor: '#005866',
                    showCancel: false,
                    success(res) {}
                })
            }
        }).catch(err => {
            wx.showToast({
                title: '请求超时',
                icon: 'none',
                duration: 3000,
                mask: false
            });
        })

    },
    submitOrder() {
        app.http(API.apiSubmitOrder, {
            car_info_save_source: 1,
            userId: this.data.userId,
            bind_tel: this.data.etcInfo.saveAccountInfoRequest.mobilephone,
            address: this.data.saveCarInfoRequest.vehicle_info_address,
            accountId: this.data.etcInfo.accountId,
            carInfoId: this.data.etcInfo.carInfoId,
            userno: this.data.etcInfo.userno,
            recharege_flag: '02',
            whether_mail: '01',
            price: 0,
            product_id: '02',
            user_type: 8,
            spe_flag: '1',
            issue_date: this.data.saveCarInfoRequest.issue_date,
            register_date: this.data.saveCarInfoRequest.register_date,
            idtype: this.data.etcInfo.saveAccountInfoRequest.idtype,
            idnum: this.data.etcInfo.saveAccountInfoRequest.idnum,
            organ: this.data.etcInfo.saveAccountInfoRequest.organ,
            owner: this.data.saveCarInfoRequest.owner,
            vehicle_plate: this.data.saveCarInfoRequest.vehicle_plate,
            vehicle_color: this.data.saveCarInfoRequest.vehicle_color,
            vehicle_type: 0,
            vehicle_axles: this.data.saveCarInfoRequest.vehicle_axles,
            vehicle_wheels: this.data.saveCarInfoRequest.vehicle_wheels,
            vehicle_txtclass: this.data.saveCarInfoRequest.vehicle_txtclass,
            func_type: this.data.saveCarInfoRequest.func_type,
            factory_code: this.data.saveCarInfoRequest.factory_code,
            engine_code: this.data.saveCarInfoRequest.engine_code,
            vehicle_code: this.data.saveCarInfoRequest.vehicle_code,
            vehicle_length: this.data.saveCarInfoRequest.vehicle_length,
            vehicle_width: this.data.saveCarInfoRequest.vehicle_width,
            vehicle_height: this.data.saveCarInfoRequest.vehicle_height,
            vehicle_code_flag: this.data.ownerType1,
            veh_license_pic_url1: this.data.saveCarInfoRequest.veh_license_pic_url1,
            veh_license_pic_url2: this.data.saveCarInfoRequest.veh_license_pic_url2,
            total_mass: this.data.saveCarInfoRequest.total_mass,
            maintenance_mass: this.data.saveCarInfoRequest.maintenance_mass,
            permitted_tow_weight: this.data.saveCarInfoRequest.permitted_tow_weight,
            vehicle_capacity: '',
            approved_count: this.data.saveCarInfoRequest.approved_count,
            owner_picurl1: this.data.saveCarInfoRequest.owner_picurl1 || '',
            owner_picurl2: this.data.saveCarInfoRequest.owner_picurl2 || '',
            owner_id_type: this.data.saveCarInfoRequest.owner_id_type || ''
        }).then(res => {
            if (res.code == 200) {
                this.getState();
            } else {
                wx.showModal({
                    title: '提示',
                    content: res.message,
                    confirmColor: '#005866',
                    showCancel: false,
                    success(res) {}
                })
                wx.hideLoading();
            }
        }).catch(err => {
            console.log(err, 'submitBusiness')
            wx.showToast({
                title: '请求超时',
                icon: 'none',
                duration: 3000,
                mask: false
            });
        })

    },
    //空函数，解决表单的事件穿透
    checkboxChange() {

    },
    //获取用户状态
    getState() {
        if (!this.data.lock) {
            wx.showLoading({
                title: '加载中...',
                mask: true
            });
            this.data.lock = true;
            app.http(API.apiGetState, {
                userId: this.data.userId
            }).then(res => {
                if (res.code == 200) {
                    let rspData = JSON.parse(res.rspData);
                    console.log(rspData);
                    var etcInfo = !rspData.jsonData || rspData.jsonData == '' ? '' : JSON.parse(rspData.jsonData)

                    if (rspData.state < 4) {
                        this.setData({
                            licensePlate: rspData.vehiclePlate,
                            phone: rspData.phone ? rspData.phone : '',
                            state: rspData.state,
                            vehiclePlate: rspData.vehiclePlate,
                            vehicle_color: rspData.vehicleColor,
                            etcInfo: etcInfo,
                            ownerType: rspData.ownerType,
                            submitOrderStatus: etcInfo.submitOrderStatus == 1 ? 1 : 0
                        }, () => {
                            if (this.data.submitOrderStatus == 1) {
                                this.toBingBank();
                            }
                            wx.hideLoading();
                        })

                    } else {
                        wx.redirectTo({
                            url: '/pages/submit_success/submit_success',
                        })

                        wx.hideLoading();

                    }

                } else {
                    wx.hideLoading();
                }
                this.data.lock = false
            }).catch(err => {
                // console.log(err)
                wx.hideLoading();
                this.data.lock = false
            })
        }
    },
    certifiChange(e) {
        if (this.data.isEdit) {
            return;
        }
        this.setData({
            certifiType: e.currentTarget.dataset.type
        })
    },
    toBingBank() {
        let etcInfo = JSON.parse(JSON.stringify(this.data.etcInfo))
        wx.redirectTo({
            url: '/pages/biddingBank/biddingBank?etcInfo=' + JSON.stringify(etcInfo),
        });
    },
    // 选择车辆ETC类型
    // changeOwnerType(e) {
    //     this.setData({
    //         ownerType1: e.detail.value
    //     })
    // },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        app.getDeviceSize().then(res => {
            const {
                bottomLift,
                windowHeight
            } = res
            this.setData({
                bottomLift,
                windowHeight
            })
        })
        let userId = wx.getStorageSync('userId') || '';
        this.setData({
            userId
        })
        this.getState();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})